﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QUANLYNHASACH
{
    public partial class frmQuanLyNXB : Form
    {
        QUANLYNHASACH.App_code.BLL.NXB_BLL bllNXB = new QUANLYNHASACH.App_code.BLL.NXB_BLL();
        public frmQuanLyNXB()
        {
            InitializeComponent();
        }

      

        private void frmQuanLyNXB_Load(object sender, EventArgs e)
        {
            Gridnxb.DataSource = bllNXB.LayDanhSachNXB();

        }


        private void bttSua_Click(object sender, EventArgs e)
        {
            bool isCheck = false;
            for (int i = 0; i < this.Gridnxb.Rows.Count; i++)
            {
                if (this.Gridnxb.Rows[i].Cells[0].Value != null)
                {
                    isCheck = (bool)this.Gridnxb.Rows[i].Cells[0].Value;
                    string idNXB = this.Gridnxb.Rows[i].Cells[1].Value.ToString();
                    string tenNXB = this.Gridnxb.Rows[i].Cells[2].Value.ToString();
                    string Diachi = this.Gridnxb.Rows[i].Cells[3].Value.ToString();
                    string nguoiDD = this.Gridnxb.Rows[i].Cells[4].Value.ToString();
                    string soDT = this.Gridnxb.Rows[i].Cells[5].Value.ToString();
                    string Email = this.Gridnxb.Rows[i].Cells[6].Value.ToString();
                    if (isCheck == true)
                    {
                        bllNXB.CapNhatNXB(idNXB, tenNXB, Diachi, nguoiDD, soDT, Email);
                    }
                }
            }
            MessageBox.Show("Đã cập nhật danh sách NXB thành công", "Thông báo");
        }

        private void bttThem_Click(object sender, EventArgs e)
        {
            string idNXB=txtID.Text;;
            string tenNXB=txtTenNXB.Text;
            string Diachi=txtDiaChi.Text;
            string nguoiDD=txtNguoiDD.Text;
            string soDT= txtSoDT.Text;
            string Email=txtEmail.Text;
            bllNXB.ThemNXB(idNXB, tenNXB, Diachi, nguoiDD, soDT, Email);
            MessageBox.Show("Đã thêm NXB thành công", "Thông báo");
            Gridnxb.DataSource = bllNXB.LayDanhSachNXB();

        }

        private void bttXoa_Click(object sender, EventArgs e)
        {
            bool isCheck = false;
            for (int i = 0; i < this.Gridnxb.Rows.Count; i++)
            {
                if (this.Gridnxb.Rows[i].Cells[0].Value != null)
                {
                    isCheck = (bool)this.Gridnxb.Rows[i].Cells[0].Value;
                    string idNXB = this.Gridnxb.Rows[i].Cells[1].Value.ToString();
                   
                    if (isCheck == true)
                    {
                        bllNXB.XoaNXB(idNXB);
                       
                    }
                    Gridnxb.DataSource = bllNXB.LayDanhSachNXB();
                }
            }
        }
    }
}
